package myjava.swing;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

/**
 * @author Yancy
 * @program springioctest
 * @create 2020-11-22
 */
public class TestMenu {
  public static void main(String[] args) {
    //
      JFrame frame = new JFrame("Menu Demo");
      JMenuBar mb = new JMenuBar();
      JMenu menu1 = new JMenu("File");
      JMenu menu2 = new JMenu("Edit");
      mb.add(menu1);
      mb.add(menu2);
      JMenuItem menuItem1 = new JMenuItem("Save", KeyEvent.VK_S);

      JMenuItem menuItem2 = new JMenuItem("Load");
      menuItem2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
      JMenuItem menuItem3 = new JMenuItem("Quit");
      menu1.add(menuItem1);
      menu1.add(menuItem2);
      menu1.addSeparator();
      menu1.add(menuItem3);
      frame.setJMenuBar(mb);
      frame.setVisible(true);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(400,400);
  }
}
